home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
X User Tools
/
X User Tools (O'Reilly and Associates)(1994).ISO
/
sun4c
/
archive
/
tcltk.z
/
tcltk
/
man
/
catn
/
regsub.n
< prev
next >
Wrap
Text File
|
1994-09-20
|
4KB
|
133 lines
regsub(n) Tcl Built-In Commands
_________________________________________________________________
NAME
regsub - Perform substitutions based on regular expression
pattern matching
SYNOPSIS
regsub ?_s_w_i_t_c_h_e_s? _e_x_p _s_t_r_i_n_g _s_u_b_S_p_e_c _v_a_r_N_a_m_e
_________________________________________________________________
DESCRIPTION
This command matches the regular expression _e_x_p against
_s_t_r_i_n_g, and it copies _s_t_r_i_n_g to the variable whose name is |
given by _v_a_r_N_a_m_e. The command returns 1 if there is a match |
and 0 if there isn't. If there is a match, then while copy- |
ing _s_t_r_i_n_g to _v_a_r_N_a_m_e the portion of _s_t_r_i_n_g that matched _e_x_p
is replaced with _s_u_b_S_p_e_c. If _s_u_b_S_p_e_c contains a ``&'' or
``\0'', then it is replaced in the substitution with the
portion of _s_t_r_i_n_g that matched _e_x_p. If _s_u_b_S_p_e_c contains a
``\_n'', where _n is a digit between 1 and 9, then it is
replaced in the substitution with the portion of _s_t_r_i_n_g that
matched the _n-th parenthesized subexpression of _e_x_p. Addi-
tional backslashes may be used in _s_u_b_S_p_e_c to prevent special
interpretation of ``&'' or ``\0'' or ``\_n'' or backslash.
The use of backslashes in _s_u_b_S_p_e_c tends to interact badly
with the Tcl parser's use of backslashes, so it's generally
safest to enclose _s_u_b_S_p_e_c in braces if it includes
backslashes.
If the initial arguments to regexp start with - then they |
are treated as switches. The following switches are |
currently supported: |
-all ||
All ranges in _s_t_r_i_n_g that match _e_x_p are found and |
substitution is performed for each of these |
ranges. Without this switch only the first match- |
ing range is found and substituted. If -all is |
specified, then ``&'' and ``\_n'' sequences are |
handled for each substitution using the informa- |
tion from the corresponding match. |
-nocase ||
Upper-case characters in _s_t_r_i_n_g will be converted |
to lower-case before matching against _e_x_p; how- |
ever, substitutions specified by _s_u_b_S_p_e_c use the |
original unconverted form of _s_t_r_i_n_g. |
-- ||
Marks the end of switches. The argument following |
this one will be treated as _e_x_p even if it starts |
Tcl 1
regsub(n) Tcl Built-In Commands
with a -.
See the manual entry for regexp for details on the interpre-
tation of regular expressions.
KEYWORDS
match, pattern, regular expression, substitute
Tcl 2